from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views.commission_category_views import CommissionCategoryViewSet
from .views.user_views import UserViewSet, test_api_endpoint
from .views.auth_views import LoginView, UserInfoView, logout, test_api
from rest_framework_simplejwt.views import TokenRefreshView
from .views.attendance_views import AttendanceViewSet
from .views.salary_views import SalaryListAPI, SalaryDetailAPI, SalaryExportAPI, CustomerServiceUserListAPI

# 创建专门的用户路由器，确保users路径优先匹配
user_router = DefaultRouter()
user_router.register(r'users', UserViewSet, basename='user')

# 常规路由器
router = DefaultRouter()
router.register(r'commission-categories', CommissionCategoryViewSet, basename='commission-category')
# router.register(r'users', UserViewSet, basename='user')  # 已经在专用路由器中注册
router.register(r'attendance', AttendanceViewSet)

# 用户视图集自定义接口的URL已经由DRF自动注册:
# /api/umm/users/profile/ - 获取或更新用户个人资料
# /api/umm/users/password/ - 修改用户密码

urlpatterns = [
    # 直接添加测试API路径 - 无需认证
    path('test-api/', test_api_endpoint, name='test_api_endpoint'), 
    
    # 直接添加用户API路径
    path('users/', UserViewSet.as_view({'get': 'list', 'post': 'create'}), name='user-list'),
    path('users/<int:pk>/', UserViewSet.as_view({'get': 'retrieve', 'put': 'update', 'patch': 'partial_update', 'delete': 'destroy'}), name='user-detail'),
    
    # 用户批量删除和导出URL
    path('users/batch-delete/', UserViewSet.as_view({'post': 'batch_delete'}), name='user-batch-delete'),
    path('users/export/', UserViewSet.as_view({'get': 'export_users'}), name='user-export'),
    
    # 添加用户导入相关URL
    path('users/import-template/', UserViewSet.as_view({'get': 'import_template'}), name='user-import-template'),
    path('users/import-data/', UserViewSet.as_view({'post': 'import_data'}), name='user-import-data'),
    
    # 同时保留路由器注册的路径
    path('', include(user_router.urls)),
    path('', include(router.urls)),
    
    # 测试API
    path('test/', test_api, name='test_api'),
    # 认证相关URL
    path('auth/login/', LoginView.as_view(), name='login'),
    path('auth/refresh/', TokenRefreshView.as_view(), name='refresh'),
    path('auth/user-info/', UserInfoView.as_view(), name='user_info'),
    path('auth/logout/', logout, name='logout'),
    
    # 薪资相关API
    path('salary/list', SalaryListAPI.as_view(), name='salary_list'),
    path('salary/detail', SalaryDetailAPI.as_view(), name='salary_detail'),
    path('salary/export', SalaryExportAPI.as_view(), name='salary_export'),
    path('salary/user-options', CustomerServiceUserListAPI.as_view(), name='customer_service_users'),
]
